package org.alex.samples.dao;

import java.util.List;

import org.alex.samples.model.ExamUserRole;
import org.alex.samples.model.User;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class UserDAOImpl extends BaseHibernateDAO<User> implements IUserDAO {
	
	@Override
	public User getUserById(String id) {
		User exsitsUser= this.get(id);
		return exsitsUser;
	}
	
	@Override
	public List<User> findAllUsers() {
		String hql="from User";
		List<User> userList = this.find(hql);
		return userList;
	}

	@Override
	public void createUser(User user) throws Exception {
		this.save(user);
	}

	@Override
	public void editUser(User user) throws Exception {
		this.update(user);
	}

	@Override
	public void delete(String id) throws Exception {
		User exsitsUser = this.get(id);
		if(exsitsUser!=null){
			this.delete(exsitsUser);
		}
	}

	@Override
	public ExamUserRole getExamUserRoleByUserId(String userId) {
//		List<ExamUserRole> er=this.createQuery("FROM ExamUserRole WHERE userId="+userId).list();
//		for (ExamUserRole e : er) {
//			return e;
//		}
//		System.out.println(er);
		return null;
	}
    
	
}

//if(users.containsKey(id)){
//return users.get(id);
//} else {
//return null;
//}

//@Override
//public void editUser(User user) throws Exception{
//	if(user !=null && users.containsKey(user.getId())){
//		users.put(user.getId(), user);
//	} else {
//		throw new  Exception("Update User Fail!");
//	}
//}

//public UserDAOImpl(){
//	users.put(1, new User(1,"alex","0","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(2, new User(2,"Jordan","1","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(3, new User(3,"Janes","0","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(4, new User(4,"Kobe","1","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(5, new User(5,"Ray","1","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(6, new User(6,"Linux","0","1995.11","15454687321","GuangdongshengHuilaixiang"));
//	users.put(7, new User(7,"CentOS","1","1995.11","15454687321","GuangdongshengHuilaixiang"));
//}

//@Override
//public List<User> findAllUsers() {
//	if(users != null){
//		return new ArrayList<User>(users.values());
//	}else{
//		return null;
//	}
//}

//@Override
//public void createUser(User user) throws Exception{
//	if(user !=null && !users.containsKey(user.getId())){
//		users.put(user.getId(), user);
//	}else{
//		throw new Exception("Create User Fail");
//	}
//}
//
//@Override
//public void delete(Integer id) throws Exception {
//	if(users.containsKey(id)){
//		users.remove(id);
//	}else{
//		throw new Exception("Delete User Fail");
//	}
//	
//}
